﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fireprefab : MonoBehaviour {

    public GameObject shell;//子弹
    public KeyCode keycode = KeyCode.Space;//按键默认空格
    private Transform firePrefab;//实例化子弹的位置
    public float shellspeed = 10f;//子弹的速度
    public AudioClip shotfir;


	void Start () {
        firePrefab = transform.Find("FirePrefab");//找到子弹的预制物
	}
	
	
	void Update () {
        if (Input.GetKeyDown(keycode))//按下默认的空格键
        {
            AudioSource.PlayClipAtPoint(shotfir, transform.position);
                                         //实例化  （子弹），实例化的位置 ，     实例化的角度
           GameObject tank = GameObject.Instantiate(shell, firePrefab.position, firePrefab.rotation);
           tank.GetComponent<Rigidbody>().velocity = tank.transform.forward * shellspeed;
        }
	}
    
}
